package org.witsoft.demo.graphql.resovler;


import graphql.kickstart.tools.GraphQLMutationResolver;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.witsoft.demo.graphql.entity.Author;
import org.witsoft.demo.graphql.entity.Book;
import org.witsoft.demo.graphql.entity.User;
import org.witsoft.demo.graphql.model.AuthorInput;
import org.witsoft.demo.graphql.model.BookInput;
import org.witsoft.demo.graphql.model.Result;
import org.witsoft.demo.graphql.model.UserInput;
import org.witsoft.demo.graphql.repository.AuthorRepository;
import org.witsoft.demo.graphql.repository.BookRepository;
import org.witsoft.demo.graphql.service.UserService;

@Component
@RequiredArgsConstructor
public class RootMutationResolver implements GraphQLMutationResolver {

    private final AuthorRepository authorRepository;
    private final BookRepository bookRepository;

    public Result<Author> saveAuthor(AuthorInput input){
        Author author = new Author();
        BeanUtils.copyProperties(input, author);
        authorRepository.save(author);
        return Result.success(author);
    }

    public Result<Book> saveBook(BookInput input){
        Book book = new Book();
        BeanUtils.copyProperties(input, book);
        bookRepository.save(book);
        return Result.success(book);
    }
}
